package code;

import java.util.Stack;

public class IsPopOrder {
    public boolean Solution(int [] pushA,int [] popA) {
        Stack<Integer> s1 = new Stack<Integer>();
        int count=0;
        for(int i = 0;i<pushA.length;i++){
            s1.push(pushA[i]);
            if(s1.peek()==popA[count]){
                s1.pop();
                count++;
            }
        }
        if(s1.size()>0){
            for(int i=count;i<popA.length;i++){
                if(popA[i]!=s1.peek()){
                    break;
                }else {
                    s1.pop();
                    count++;
                }
            }
        }
        if (count==popA.length){
            return true;
        }
        else {
            return false;
        }
    }
}
